import pytesseract
from PIL import Image, ImageEnhance


def binaryzation(threshold=145):  # 降噪，图片二值化
    table = []
    for i in range(256):
        if i < threshold:
            table.append(0)
        else:
            table.append(1)

    return table


image = Image.open('code.jpg')  # 打开图片
image = image.convert('L')  # 转化为灰度图
image = image.point(binaryzation(), '1')  # 二值化
image.show()
